using System.Transactions;
using PetShop.BusinessEntities;
using PetShop.BusinessEntityManagers;

namespace PetShop.BusinessFacade
{
    public class AccountFacade
    {
        public AccountInfo SignIn(string userId, string password)
        {
            if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(password))
                return null;
            var bo = new AccountBO();
            AccountInfo account = bo.SignIn(userId, password);
            return account;
        }


        public void CreateNewAccount(AccountInfo account)
        {
            if (string.IsNullOrEmpty(account.UserId))
                return;
            using (var ts = new TransactionScope(TransactionScopeOption.Required))
            {
                var bo = new AccountBO();
                bo.Insert(account);
                ts.Complete();
            }
        }

        public void UpdateAccount(AccountInfo account)
        {
            if (account == null)
                return;
            using (var ts = new TransactionScope(TransactionScopeOption.Required))
            {
                var bo = new AccountBO();
                bo.Update(account);
                ts.Complete();
            }
        }
    }
}